package org.jeecg.modules.hotel.belongToSkd.controller;



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;



/**
 * @Description:
 * @author:MJ-BaBa
 * @date: 2022.12.27
 */
@Api(tags = "山科大宿舍进出通断电")
@RestController
@RequestMapping("/belongToSkd")
@Slf4j
public class LwgyHotelEventController {


    @AutoLog(value = "海康-按事件类型订阅事件")
    @ApiOperation(value="海康-按事件类型订阅事件",notes = "海康-按事件类型订阅事件")
    @PostMapping(value = "/inAndOutOutage")
    public static String inAndOutOutage() {
        //路径
        ArtemisConfig.host = "192.168.100.46:443"; // artemis 网关服务器 ip 端口
        ArtemisConfig.appKey = "21414884"; // 秘钥 appkey
        ArtemisConfig.appSecret = "bmHp85fldMEbAwDrUYJ9";// 秘钥 appSecret

        final String ARTEMIS_PATH = "/artemis";
        final String queryDcmsRecordCountApi = ARTEMIS_PATH +
                "/api/eventService/v1/eventSubscriptionByEventTypes";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", queryDcmsRecordCountApi);//根据现场环境部署确认是 http 还是https
            }
        };
        String contentType = "application/json";
        //传参
        JSONObject jsonBody = new JSONObject();

        JSONArray eventTypes = new JSONArray();
        eventTypes.add(1208156168);
        jsonBody.put("eventTypes", eventTypes);
        jsonBody.put("subWay", 1);
        jsonBody.put("eventDest", "http://192.168.100.120:8080/jeecg-boot/belongToSkd/receiveData");
        String body = jsonBody.toJSONString();
        //result : 这是返回的数据
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null,
                contentType , null);// post请求application/json类型参数
        return result;
    }

    public static void main(String[] args) {
        String result = inAndOutOutage();
        System.out.println("result=======" + result);
    }

}
